<?

$check_me_authed = "NO_OK";	

if(($jid = $_POST["radioview"]) || ($jid = $_POST["job_id_posted"]) ){
	
	unset($COracle);
	
	$COracle = new oracleDb;
  $COracle->init($_SESSION["ORCL"], 
                 $_SESSION["OPASS"],
                 $_SESSION["SID"],
                 _NO_COMMENT);
  
	if ($COracle->connect()) {
		
		$srcDbMstCategory   = "MST_MODEL_CAT";
    $srcDbMstGroup      = "MST_MODEL_GRP";
  	$srcDbHdr			      = "SLS_RET_HDR";
    $srcDbHdrLog	      = "LOG_SLS_HDR";
    $srcDbDtl           = "SLS_RET_DTL";
		
		$_SESSION["jid"]  = $_POST["radioview"];
		$jobId            = &$_SESSION["jid"];
		
		/**
		* Fetch global header
		* And check the status if it is valid
		* where STATUS = _NOT_ACTIVE
		*
		*/
		$CFetchers->fetchLstDataHeader($COracle,
                                   $jobId,
                                   $srcDbHdr,
                                   $nHeader,
                                   $lstHeader);
                       
		if($lstHeader["STATUS"][0] == _NOT_ACTIVE ||
		   $lstHeader["STATUS"][0] == _CANCELED){
  		
  		/**
  		* Init the header vars
  		*
  		*/
  		$_POST["trDateEnt"]     = date("d-m-Y",
  		                               strtotime($lstHeader["TR_DATE"][0]));
  		
  		/**
  		* Init the detail
  		*
  		*/
  		$CFetchers->fetchLstDataDetail($COracle,
                                     $jobId,
                                     $srcDbDtl,
                                     $nDetail,
                                     $lstDetail);
              		
  		for($iRow = 0; $iRow < $nDetail; $iRow++){
  		  
  		  $_POST["modelEnt"][$iRow]  = $lstDetail["MODEL"][$iRow];
  		  $_POST["qtyEnt"][$iRow]    = $lstDetail["QTY"][$iRow];
  		  $_POST["serNumEnt"][$iRow] = $lstDetail["SER_NUMBER"][$iRow];
  		  $_POST["reasonEnt"][$iRow] = $lstDetail["REASON"][$iRow];
  		}
  		
  		/**
  		* Check if this tx isn't canceled
  		* YES: it is modify
  		* NO : Add new entry with this copy
  		*
  		*/
  		if($lstHeader["STATUS"][0] != _CANCELED){
  		  
  		  $_SESSION["modify_mode"]= "Y";
  		}else{
  		  
  		  $_SESSION["modify_mode"]= "N";
  		}
  		
  		/**
  		* This is only to by pass
  		* the entry_detail precheck
  		*
  		*/
  		//$_POST["entry"]         = "byPass";  
  		$_SESSION["init_num"]   = $nDetail;
  		
  		$COracle->dc();
  		
  		require("entry_restore_me.php");
  	
  	}else{
  	  
  	  usrDie("Tx can't be modified, it has been approved");
  	}
	}else{
	  
	  usrDie("Error: Oracle connection failed");
	}
}else{
	
	usrDie("Error:Cant retrieved job_id");
}

?>